package com.zcb.qingshoudan.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.xys.libzxing.zxing.encoding.EncodingUtils;
import com.zcb.qingshoudan.R;

public class GatheringQRCodeActivity extends Activity implements View.OnClickListener{

    private LinearLayout titleLinearLayout;
    private TextView titleTV;
    private ImageView QRCode;
    private int h = 200;
    private int i = 200;
    private Bitmap j;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_gathering_qrcode);
        initView();
        Intent intent=getIntent();
        String QRCodeInfo=intent.getStringExtra("QRCodeInfo");
        make(QRCode,QRCodeInfo);
    }


    private void initView(){
        titleLinearLayout= (LinearLayout) findViewById(R.id.title_lin_back);
        titleTV= (TextView) findViewById(R.id.title_text);
        titleLinearLayout.setVisibility(View.VISIBLE);
        titleLinearLayout.setOnClickListener(this);
        titleTV.setText("二维码");
        QRCode= (ImageView) findViewById(R.id.gathering_qrcode_code);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.title_lin_back:
                finish();
                break;
        }
    }

    //生成二维码 可以设置Logo
    public void make(View view,String input) {

        if (input.equals("")){
            Toast.makeText(this,"输入不能为空",Toast.LENGTH_SHORT).show();
        }else{
            Bitmap qrCode = EncodingUtils.createQRCode(input, 500, 500,null);
            QRCode.setImageBitmap(qrCode);
        }
    }
}
